package com.loongtech.bi.manager.pay;

import com.loongtech.bi.entity.pay.EntityNewUserLTV;
import com.loongtech.bi.entity.pay.EntityNewUserLTVTag;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewUserLTVManager extends ManagerQueryCacheBase<EntityNewUserLTV> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间，求付费LTV对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNewUserLTV> getAllNewUserLTVByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("from EntityNewUserLTV where 1=1 and startday>=:dayStart and endday=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"'", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
	
	/**
	 * 根据开始结束时间，求付费LTV对象，比结束时间大59天（60日LTV）
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNewUserLTV> getAllNewUserLTVByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityNewUserLTV where 1=1 and startday>=:dayStart and startday<=:dayStart1 and endday<=:dayEnd", "dayStart", Time.getDateStr(dateStart), "dayStart1", Time.getDateStr(dateEnd), "dayEnd", Time.getDateStr(new Date(dateEnd.getTime() + 119 * Time.DAY)));
	}

    public List<EntityNewUserLTV> getChannelNewUserLTVByDate(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityNewUserLTV where 1=1 and startday>=:dayStart and startday<=:dayStart1 and endday<=:dayEnd and channelid != '0' ", "dayStart", Time.getDateStr(dateStart), "dayStart1", Time.getDateStr(dateEnd), "dayEnd", Time.getDateStr(new Date(dateEnd.getTime() + 119 * Time.DAY)));
    }

    /**
     * 根据开始结束时间，求付费LTV对象，比结束时间大59天（60日LTV）
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityNewUserLTVTag> getAllNewUserLTVByDateByTag(String serverid, Date dateStart, Date dateEnd) {
        return findByQuery("from EntityNewUserLTVTag where serverid=? and startday>=? and startday<=? and endday<=?", serverid, Time.getDateStr(dateStart), Time.getDateStr(dateEnd), Time.getDateStr(new Date(dateEnd.getTime() + 119 * Time.DAY)));
    }


    public List<EntityNewUserLTV> getAllNewUserLTVByAllKindOneDay(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
        return findByQuery("from EntityNewUserLTV where 1=1 and startday>=:dayStart and startday<=:dayEnd and startday=endday and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"'", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
    }
}
